package com.ct.ah.lab.controller;

import com.ct.ah.lab.entity.Assess;
import com.ct.ah.lab.entity.Category;
import com.ct.ah.lab.entity.User;
import com.ct.ah.lab.entity.vo.CashItemVo;
import com.ct.ah.lab.service.IAssessService;
import com.ct.ah.lab.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/assess")
public class AssessController {
    @Autowired
    private IAssessService assessService;

    @RequestMapping("/save")
    @ResponseBody
    public Map<String,Object> save(Integer all,Integer happy,Integer deliver,Integer serve,String msg, Integer oid ,HttpServletRequest req){
        Map<String, Object> map = new HashMap<>();
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("loginUser");
        if (user == null) {
           map.put("msg", "not login");
        } else {
            assessService.save(all,happy,deliver,serve,msg,oid,user);
            map.put("state", 1000);
        }
        return map;

    }
    @RequestMapping("/getAccessByOid")
    @ResponseBody
    public Map<String,Object> getAccessByOid(Integer oid ,HttpServletRequest req){
        Map<String, Object> map = new HashMap<>();
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("loginUser");
        if (user == null) {
            map.put("msg", "not login");
        } else {
            Assess accessByOid = assessService.getAccessByOid(oid, user);
            System.out.println(accessByOid.toString());
            if(accessByOid!=null){
                map.put("state", 1000);
                map.put("data", accessByOid);
                map.put("msg", true);
            }else{
                map.put("msg", false);
            }
        }
        return map;

    }
}
